//JavaScript代码区域
layui.use(['element', 'carousel', 'form','layer'], function() {
    var form = layui.form,
        element = layui.element;
    $ = layui.$;

    //验证当前用户是否登录
    var _ticket = $.cookie("token");
    if(_ticket != null || _ticket != ""){
        $.ajax({
            url : "http://localhost:8083/user/token/" + _ticket,//单点登录链接
            dataType : "jsonp",
            type : "GET",
            success : function(data){
                if (data.code == 200) {
                    window.username = data.data.user.loginName;
                    $("#cur-user").html(username);
                } else {
                    layer.confirm('用户登录已过期，请中重新登录', {icon: 3, title: '提示信息'}, function (tips) {});
                    window.location.href = "http://localhost:8083/login";
                }
            }
        });
    } else {
        layer.confirm('用户登录已过期，请中重新登录', {icon: 3, title: '提示信息'}, function (tips) {});
        window.location.href = "http://localhost:8083/login";
    }

    /*-----------------------------------------------------*/
    //旁栏收缩效果
    let LeftStyle = "position:absolute;right:0;z-index:998;overflow:hidden;";
    let RightStyle = "position:absolute;right:0;z-index:998;overflow:hidden;left:44px;";
    $('.layui-layout-left').children('li').eq(0).on('click',function(){
        if($(this).find('i').hasClass('layui-icon-shrink-right') == true){
            $(this).find('i').removeClass('layui-icon-shrink-right').addClass('layui-icon-spread-left');
            // 旁栏为收缩状态
            $("#main-nav .layui-nav-item a span").hide();
            $('.layui-bg-black').animate({"width": 60}, 300);
            $('.layui-right').attr("style",LeftStyle);
            $('.layui-right').animate({"width":$('.layui-right').width()+156, "left":60}, 300);
            $('.layui-logo').text("").css({"background":"#1389b4 url(./static/img/logo.png) no-repeat center "});
            $('.layui-logo').animate({"width":60}, 300);
            $('.layui-layout-left').animate({"left":60}, 300);
            $('.layui-layout-admin .layui-footer').animate({"left":60}, 300);
            $(".layui-nav-tree").css("width",67);
            //如果有打开的标签就关闭
            $("#main-nav li").removeClass('layui-nav-itemed');
        }
        else{
            $(this).find('i').removeClass('layui-icon-spread-left').addClass('layui-icon-shrink-right');
            // 旁栏为展开状态
            $("#main-nav .layui-nav-item a span").show();
            $('.layui-bg-black').animate({"width": 200}, 300);
            $('.layui-right').attr("style",RightStyle);
            $('.layui-right').animate({"width":$('.layui-right').width()-156, "left":200}, 300);
            $('.layui-logo').animate({"width":200}, 300, function(){
                $('.layui-logo').removeAttr('style').attr("style","background-color:#1389b4;").text("智慧农业云服务");

            });
            $('.layui-layout-left').animate({"left":200}, 300);
            $(".layui-nav-tree").css("width",200);
        }

    });
    $("#main-nav li").click(function () {
        if (!$("#LAY_app_flexible").hasClass('layui-icon-shrink-right')) {
            $("#LAY_app_flexible").removeClass('layui-icon-spread-left').addClass('layui-icon-shrink-right');
            // 旁栏为展开状态
            $("#main-nav .layui-nav-item a span").show();
            $('.layui-bg-black').animate({"width": 200}, 300);
            $('.layui-right').attr("style",RightStyle);
            $('.layui-right').animate({"width":$('.layui-right').width()-156, "left":200}, 300);
            $('.layui-logo').animate({"width":200}, 300, function(){
                $('.layui-logo').removeAttr('style').attr("style","background-color:#1389b4;").text("智慧农业云服务");
            });
            $('.layui-layout-left').animate({"left":200}, 300);
            $(".layui-nav-tree").css("width",200);
        }
    });

    //左侧菜单提示信息
    $("#main-nav li a").hover(function () {
        if (!$("#LAY_app_flexible").hasClass('layui-icon-shrink-right')) {
            layer.tips($(this).find("span").html(), this);
        }
    });


});




